package com.mxue.test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();

        list.add("wang");
        list.add("ye");
        list.add("xin");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            iterator.next();//少了这个,后续的remove 没法执行
            iterator.remove();
            System.out.println("已经删除");
        }
        System.out.println(list);
    }
}
